<?php
namespace app\admin\controller\finance;
use app\admin\controller\Controller;
use app\common\model\divide\Receive as ReceiveModel;

/**
 * 用户分红记录
 * Class System
 * @package app\admin\controller\abonus
 */
class User extends Controller
{

    /**
     * @return string
     */
    public function index()
    {
        $model = new ReceiveModel();
        return $this->fetch('index', [
            // 充值记录列表
            'list' => $list = $model->getAllList($this->request->param()),
            // 属性集
            'statusList' => $model::getStatuslist(),

        ]);
    }

    public function detail($id=null){
        $model = new ReceiveModel();
        $wxappId = db('divide_receives')->where('receives_id', $id)->value('wxapp_id');
        $serviceType = db('wxapp')->where('wxapp_id', $wxappId)->value('service_type');
        if(1 == $serviceType) {
            $list = db('divide_receives_user')->where('receives_id', $id)->find();
            if($list) {
                $list = json_decode($list['extend'],true);
                array_walk($list, function(&$item){
                    $item['refund_type'] = $item['type'];
                    $item['create_time'] = $item['time'];
                });
            }
        }elseif(2 == $serviceType) {
            $list = db('divide_receives_log')->where('receives_id',$id)->select();
            if($list) {
                $list = $list->toArray();
            }
        }else {
            $list = [];
        }
        return $this->fetch('detail',  [
            // 充值记录列表
            'data' => $model->getList($id)->toArray(),
            // 属性集
            'list' =>$list
        ]);
    }

}